﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JKF.BusinessLayer.BLL;
using JKF.Substructure;

namespace JKF.Web.SMS.Remind
{
    public partial class SendRemandSms : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MODULE_NAME_EN = "REMIND";
        }
        #region Builder
        private StringBuilder optionBuilder = new StringBuilder();
        private bllSMS_TEMPLEATE SmsTemplateMgr = new bllSMS_TEMPLEATE();
        private bllSMS_ACCOUNT SmsAccountMgr = new bllSMS_ACCOUNT();
        public string MobileNums
        {
            get { return P("mobile"); }
        }
        #endregion

        #region Options

        /// <summary>
        /// Load SmsTemplate user can view
        /// </summary>
        public string SmsTemplates
        {
            get
            {
                optionBuilder.Clear();
                var availableTemplates = SmsTemplateMgr.GetListArray(
                    string.Format(
                        "STATUS='1' AND (IS_SHARE='1' OR SHOP_CODE IN(SELECT SHOP_CODE FROM SYS_USER_SHOP WHERE USER_KEY='{0}'))",
                        bllSYS_USER.CurrentUser.USER_KEY)
                    );

                foreach (var templeatEinfo in availableTemplates)
                {
                    optionBuilder.AppendFormat("<option value=\"{0}\" cont=\"{2}\">{1}</option>",
                        templeatEinfo.ID,
                        Server.HtmlEncode(templeatEinfo.TEMPLEATE_NAME),
                        Server.HtmlEncode(templeatEinfo.CONTENT).Replace("\"", "‘")
                    );
                }
                return optionBuilder.ToString();
            }
        }

        /// <summary>
        /// 当前账户信息
        /// </summary>
        public string CurrentAccount
        {
            get
            {
                var accList = SmsAccountMgr.GetListArray(
                    string.Format(" SHOP_CODE='{0}'",
                    bllSYS_USER.CurrentUser.SHOP_CODE));
                if (accList.Count <= 0)
                {
                    return "null";
                }
                else
                {
                    accList[0].SMS_PWD = "";
                    return accList[0].ToJson();
                }
            }
        }
        #endregion
    }
}